
import threading
from time import sleep


def fn1():
    with cond:
        for i in range(10):
            sleep(1)
            print(threading.current_thread().name, i)
            if i == 5:
                cond.wait()


def fn2():
    with cond:
        for i in range(10):
            sleep(2)
            print(threading.current_thread().name, i)
            cond.notify()  # 通知


cond = threading.Condition()  # 线程条件变量

threading.Thread(target=fn1).start()
threading.Thread(target=fn2).start()
